<template>
	<div class="widgets bg-white">
		<el-date-picker v-model="startTime" type="date" placeholder="选择开始时间" class="search__input el-input" @change="filterStartTime"></el-date-picker>
		<span style="margin-right: 12px;">到</span>
		<el-date-picker v-model="endTime" type="date" placeholder="选择结束时间" class="search__input el-input" @change="filterEndTime"></el-date-picker>
		<el-button type="primary" v-if="!startTime || !endTime" disabled>查询</el-button>
		<el-button type="primary" v-else @click="search">查询</el-button>
		<div class="btn-group right">
			<el-button type="info" @click="refresh">刷新</el-button>
			<el-button-group class="btn-other">
                <el-button v-if="multipleSelection.length == 0" disabled>
                    <img src="../../../assets/images/export.png" alt="">
                </el-button>
                <el-button title="导出" v-else @click="exportExcel">
                    <img src="../../../assets/images/export.png" alt="">
                </el-button>                     
                <el-button title="打印">
                    <img src="../../../assets/images/print.png" alt="">
                </el-button>
                <el-button title="帮助">
                    <img src="../../../assets/images/help.png" alt="">
                </el-button>
            </el-button-group>
		</div>
	</div>
</template>
<script>
export default {
	data() {
		return {
			startTime: '',
			endTime: '',
			multipleSelection: this.$store.state.netLogStore.multipleSelection,
			selectRowId: this.$store.state.netLogStore.selectRowId
		}
	},
	methods: {
		search() {
			if(new Date(this.startTime).getTime() >= new Date(this.endTime).getTime()) {
				this.$message({message: '起始时间不能大于等于结束时间', type: 'warning', duration: 1500});
				return false;
			}
			this.$http.get('openrationLog/selectOpenrationLogByDate?benginTime=' + this.startTime + '&endTime=' + this.endTime).then(res => {
                if(res.data.code === 20001) {
                	if(res.data.data) {
                		this.$store.commit('netLogStore/updateStatus', 1);		//更新当前状态， 1 === 对搜索结果进行分页
                		this.$store.commit('netLogStore/updateTotal', res.data.data.length);			//更新条目总数
                		this.$store.commit('netLogStore/updateSearchResult', res.data.data);			//保存搜索结果
                	}
                }
            }).catch(err => {
            	this.$message.err(err);
            });
		},
		refresh() {			//刷新
            this.startTime = '';
            this.endTime = '';
            this.$store.commit('netLogStore/updateStatus', 0);
            this.$store.commit('netLogStore/updateCurrentPage', 1);
            this.$store.dispatch('netLogStore/getTableData');
		},
		filterStartTime(val) {
			let date = new Date(val);
			this.startTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
		},
		filterEndTime(val) {
			let date = new Date(val);
			this.endTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
		},
		exportExcel() {			//导出
            var idSting = this.selectRowId.join(',');           //将[1,2,3]格式转为 "1,2,3"
            this.$http.get('openrationLog/export',{params: { list: idSting }}).then(res => {
                this.$message({message: '导出成功', type: 'success', duration: 1500});
                window.location.href = this.$url + 'openrationLog/export?list=' + idSting;          //导出时触发
            }).catch(err => {
                this.$message.error(err);
            });
		}
	}
}
</script>